package com.glink.manage.service.Impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glink.manage.domain.MenuFunctionUriBean;
import com.glink.manage.mapper.MenuFunctionUriMapper;
import com.glink.manage.service.MenuFunctionUriService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : qiushaoshan
 * @create 2024/6/24 9:09
 */
@Service
@Slf4j
public class MenuFunctionUriServiceImpl extends ServiceImpl<MenuFunctionUriMapper, MenuFunctionUriBean> implements MenuFunctionUriService {
    /**
     * 根据菜单ID获取地址列表
     *
     * @param menuId 菜单ID
     * @return 地址列表
     */
    @Override
    public List<String> findUriByMenuId(String menuId) {
        return this.lambdaQuery().eq(MenuFunctionUriBean::getMenuId, menuId).list().stream().map(MenuFunctionUriBean::getUri).collect(Collectors.toList());
    }

    /**
     * 根据菜单ID删除地址信息
     *
     * @param menuId 菜单ID
     * @return 删除状态
     */
    @Override
    public boolean deleteByMenuId(String menuId) {
        List<MenuFunctionUriBean> menuFunctionUriBeanList = this.lambdaQuery().eq(MenuFunctionUriBean::getMenuId, menuId).list();
        if(CollectionUtils.isNotEmpty(menuFunctionUriBeanList)){
            return this.lambdaUpdate().eq(MenuFunctionUriBean::getMenuId, menuId).remove();
        }else{
            return true;       
        }
    }
}
